const {TopClient} = require('../lib/api/topClient')
const serverConfig = require('../server.config')


class TBPlus extends TopClient {
    /**
     * @desc 基础类
     * @param apiName
     */
    constructor(apiName) {
        let dC = {
            'appkey': process.env.AA_TB_APPKEY,
            'appsecret': process.env.AA_TB_APPSECRET,
            'url': `http://gw.api.taobao.com/router/rest`
        }
        super(dC);
        this.apiName = apiName
    }

    timeCheck = {
        timeStamp: 0,
        maxBufferTime: 1000 * 60 * 2,
        do(maxBufferTime) {
            maxBufferTime = maxBufferTime || this.maxBufferTime
            console.log({maxBufferTime, timeStamp: this.timeStamp, now: new Date().getTime()})
            if ((new Date().getTime() - this.timeStamp) < maxBufferTime) {
                return false
            }

            this.timeStamp = new Date().getTime()
            return true
        },
        reset() {
            this.timeStamp = 0
            return true
        }
    }
}


class GetList extends TBPlus {
    constructor(apiName) {
        super();
        this.apiName = apiName
    }

    generateParams({
                       page_size,
                       page_no,
                       adzone_id,
                       material_id ='39313',
                       device_value,
                       device_encrypt,
                       device_type,
                       content_id,
                       content_source,
                       item_id,
                       favorites_id
                   }) {
        console.log(Object.keys(params))
    }

    /**
     *
     * @param params
     * @returns {Promise<Array>}
     */
    exec(params) {
        return new Promise((resolve, reject) => {
            this.execute(this.apiName, params, (err, data) => {
                if (err) return reject(err)
                return resolve(data)
            })
        })
    }
}


module.exports = {
    GetList
}

